/**
 * @param {number[]} bills
 * @return {boolean}
 */
var lemonadeChange = function(bills) {
  let fiveCount = 0, tenCount = 0, twentyCount = 0;
  for(let i = 0; i < bills.length; i++) {
    if(bills[i] == 5) {
      fiveCount++;
    } else if(bills[i] == 10) {
      if(fiveCount) {
        fiveCount--;
        tenCount++;
      } else {
        return false;
      }
    } else {
      if(tenCount) {
        tenCount--;
        if(fiveCount) {
          fiveCount--;
          twentyCount++;
        } else {
          return false;
        }
      } else {
        if(fiveCount >= 3) {
          fiveCount -= 3;
          twentyCount++;
        } else {
          return false;
        }
      }
    }
  }
  return true;
};
let bills = [5,5,5,10,20];
console.log(lemonadeChange(bills));
bills = [5,5,10,10,20];
console.log(lemonadeChange(bills));
